/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       paint_surface.h

	$Header: /game/paint_surface.h $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "paint_surface.h"
#include "gdi_object_selector.h"

// ------------------------------------------------------------
// abstract class to facilitate window painting
// ------------------------------------------------------------
t_paint_surface::t_paint_surface( t_screen_point window_origin, t_screen_rect const& rect, t_memory_bitmap16_ptr bitmap, t_memory_bitmap16_ptr buffer )
{
	m_window_origin = window_origin;
	m_screen_rect = rect;
	m_buffer_changed = false;  
  m_bitmap = bitmap;
	m_buffer = buffer;
}

// ------------------------------------------------------------
// abstract class to facilitate window painting
// ------------------------------------------------------------
t_paint_surface::~t_paint_surface()
{
}

// ------------------------------------------------------------
// buffered class for drawing in a windowed environment
// ------------------------------------------------------------
t_abstract_bitmap16_ptr t_paint_surface::get_bitmap()
{
  m_buffer_changed = true;
  return m_bitmap;
}

// ------------------------------------------------------------
// abstract class to facilitate window painting
// ------------------------------------------------------------
void t_paint_surface::draw( t_screen_point const& point, t_abstract_bitmap16 const& source, t_screen_rect const& source_rect )
{
	t_abstract_bitmap16_ptr	dest = get_bitmap();
	t_screen_point          dest_point = point - get_rect().top_left();

	::draw( *dest, dest_point, source, source_rect );
}

// ------------------------------------------------------------
// buffered class for drawing in a windowed environment
// ------------------------------------------------------------
void t_paint_surface::copy_buffer()
{
  if (!m_buffer_changed)
    return;

	::draw( *m_buffer, m_screen_rect.top_left(), *m_bitmap, t_screen_rect(0, 0, m_screen_rect.width(), m_screen_rect.height()) );

  m_buffer_changed = false;
}